package cn.chenc.framework.demo.service.impl;

import cn.chenc.framework.demo.entity.User;
import cn.chenc.framework.security.model.SecurityLoginUser;
import cn.chenc.framework.security.util.SecurityUtil;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 　@description: TODO
 * 　@author secret
 * 　@date 2021/4/30 11:51
 *
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = new User();
        user.setUsername(username);
        user.setPassword(SecurityUtil.encryptPassword("123456"));
        return createLoginUser(user);
    }

    public UserDetails createLoginUser(User user) {
        return new SecurityLoginUser(user, null);
    }

}
